package net.hhk.twitter;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;

import net.hhk.connect.HTTPConnect;
import net.hhk.controller.TweetAdapter;
import net.hhk.controller.TweetManager;
import net.hhk.data.User;
import android.app.TabActivity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TabHost;

public class MainActivity extends TabActivity implements OnClickListener {
	private Button btnHome, btnConnect, btnDis, btnPro;
	private LinearLayout tab1, tab2, tab3, tab4;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.home_layout);
		Intent intenthome = new Intent().setClass(this, HomeActivity.class);
		Intent intentProfile = new Intent().setClass(this,
				ViewProfileActivity.class);
		Intent intentConnect = new Intent().setClass(this,
				ConnectActivity.class);
		TabHost tabHost = getTabHost();
		tabHost.addTab(tabHost.newTabSpec("home").setIndicator("Home")
				.setContent(intenthome));
		tabHost.addTab(tabHost.newTabSpec("connect").setIndicator("Connect")
				.setContent(intentConnect));
		tabHost.addTab(tabHost.newTabSpec("discover").setIndicator("Discover")
				.setContent(intenthome));
		tabHost.addTab(tabHost.newTabSpec("profile").setIndicator("Profile")
				.setContent(intentProfile));
		Bundle b = getIntent().getExtras();
		// int value = b.getInt("id");

		LinearLayout write_tweet = (LinearLayout) findViewById(R.id.home_write_tweet);
		write_tweet.setOnClickListener(clickWriteTweet);
		Button btn = (Button) findViewById(R.id.btn_tweet);
		btn.setOnClickListener(clickWriteTweet);
		
		LinearLayout searchLayout = (LinearLayout) findViewById(R.id.btnSearch_layout);
		searchLayout.setOnClickListener(clickSearch);
		Button btnSearch = (Button) findViewById(R.id.btn_search);
		btnSearch.setOnClickListener(clickSearch);
		setupUI();
	}

	private OnClickListener clickWriteTweet = new OnClickListener() {

		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent i = new Intent(getApplicationContext(),
					WriteTweetActivity.class);
			Bundle b = new Bundle();

			b.putInt("isReply", 0);
			i.putExtras(b);
			startActivity(i);

		}
	};
	private OnClickListener clickSearch = new OnClickListener() {

		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent i = new Intent(getApplicationContext(), SearchActivity.class);

			startActivity(i);

		}
	};

	private void setupUI() {
		tab1 = (LinearLayout) findViewById(R.id.tab1);
		tab1.setOnClickListener(this);
		tab2 = (LinearLayout) findViewById(R.id.tab2);
		tab2.setOnClickListener(this);
		tab3 = (LinearLayout) findViewById(R.id.tab3);
		tab3.setOnClickListener(this);
		tab4 = (LinearLayout) findViewById(R.id.tab4);
		tab4.setOnClickListener(this);
//		Button btnSearch = (Button) findViewById(R.id.btn_search);
//		btnSearch.setOnClickListener(this);
		btnHome = (Button) findViewById(R.id.button1);
		btnHome.setOnClickListener(this);
		btnConnect = (Button) findViewById(R.id.button2);
		btnConnect.setOnClickListener(this);
		btnDis = (Button) findViewById(R.id.button3);
		btnDis.setOnClickListener(this);
		btnPro = (Button) findViewById(R.id.button4);
		btnPro.setOnClickListener(this);

	}

	public void onClick(View v) {

		switch (v.getId()) {
		case R.id.button1:
			getTabHost().setCurrentTab(0);
			tab1.setBackgroundResource(R.drawable.bg_tabbar_selected);
			tab2.setBackgroundResource(R.drawable.bg_tabbar_tile);
			tab3.setBackgroundResource(R.drawable.bg_tabbar_tile);
			tab4.setBackgroundResource(R.drawable.bg_tabbar_tile);
			btnHome.setBackgroundResource(R.drawable.ic_tab_home_active_default);
			btnConnect.setBackgroundResource(R.drawable.ic_tab_connect_default);
			btnDis.setBackgroundResource(R.drawable.ic_tab_discover_default);
			btnPro.setBackgroundResource(R.drawable.ic_tab_me_default);
			break;
		case R.id.button2:
			getTabHost().setCurrentTab(1);
			tab1.setBackgroundResource(R.drawable.bg_tabbar_tile);
			tab2.setBackgroundResource(R.drawable.bg_tabbar_selected);
			tab3.setBackgroundResource(R.drawable.bg_tabbar_tile);
			tab4.setBackgroundResource(R.drawable.bg_tabbar_tile);
			btnHome.setBackgroundResource(R.drawable.ic_tab_home_default);
			btnConnect
					.setBackgroundResource(R.drawable.ic_tab_connect_active_default);
			btnDis.setBackgroundResource(R.drawable.ic_tab_discover_default);
			btnPro.setBackgroundResource(R.drawable.ic_tab_me_default);
			break;
		case R.id.button3:
			getTabHost().setCurrentTab(2);
			tab1.setBackgroundResource(R.drawable.bg_tabbar_tile);
			tab2.setBackgroundResource(R.drawable.bg_tabbar_tile);
			tab3.setBackgroundResource(R.drawable.bg_tabbar_selected);
			tab4.setBackgroundResource(R.drawable.bg_tabbar_tile);
			btnHome.setBackgroundResource(R.drawable.ic_tab_home_default);
			btnConnect.setBackgroundResource(R.drawable.ic_tab_connect_default);
			btnDis.setBackgroundResource(R.drawable.ic_tab_discover_active_default);
			btnPro.setBackgroundResource(R.drawable.ic_tab_me_default);
			break;
		case R.id.button4:
			getTabHost().setCurrentTab(3);
			tab1.setBackgroundResource(R.drawable.bg_tabbar_tile);
			tab2.setBackgroundResource(R.drawable.bg_tabbar_tile);
			tab3.setBackgroundResource(R.drawable.bg_tabbar_tile);
			tab4.setBackgroundResource(R.drawable.bg_tabbar_selected);
			btnHome.setBackgroundResource(R.drawable.ic_tab_home_default);
			btnConnect.setBackgroundResource(R.drawable.ic_tab_connect_default);
			btnDis.setBackgroundResource(R.drawable.ic_tab_discover_default);
			btnPro.setBackgroundResource(R.drawable.ic_tab_me_active_default);
			break;

		default:
			break;
		}
	}

}